'use strict'

let fs=require('fs');

let {sequelize}=require('../db');

//筛选文件
function searchFiles(){
      let files=fs.readdirSync(__dirname);

      return files.filter(name=>{
          return name.endsWith('.js')&&name!=='index.js'
      })
}

function registerModels(files){
       let obj={};
       files.forEach(name=>{
           let modelName=name.substring(0,name.length-3);
           obj[modelName]=require(__dirname+'/'+modelName);
       })

       return obj;
}

let files=searchFiles();

let obj=registerModels(files);

obj.sync=async()=>{
    return sequelize.sync({force:true})
}

module.exports=obj;